import pathlib
import re
from collections import ChainMap


def read_file():
    hp = pathlib.Path.cwd()
    np = hp / 'test2'
    print(np)
    d = {}
    with np.open(mode='r', encoding="utf-8") as f:
        lines = f.readlines()
        for line in lines:
            s = re.split("\s+", line)
            bankNo = s[0]
            bankName = s[1]
            if bankName:
                # tmp = {}
                # tmp["bankNo"] = bankNo
                # tmp["bankName"] = bankName
                # d[bankNo] = tmp
                sql = f"INSERT INTO mall_order.bank_sam (BANK_NO, BANK_NAME) VALUES ('{bankNo}', '{bankName}');"
                print(sql)
    return d


def read_file2():
    hp = pathlib.Path.cwd()
    np = hp / 'test4'
    print(np)
    d = {}
    with np.open(mode='r', encoding="utf-8") as f:
        lines = f.readlines()
        for line in lines:
            s = re.split("\s+", line)
            bankSid = s[0]
            bankNo = s[2]
            bankName = s[1]
            if bankName:
                # tmp = {}
                # tmp["bankNo"] = bankNo
                # tmp["bankName"] = bankName
                # d[bankNo] = tmp
                sql = f"INSERT INTO mall_order.seller_channel_bank (bank_sid, channel_id, bank_code, bank_name) VALUES ({bankSid}, 4, '{bankNo}', '{bankName}');"
                print(sql)
    return d


def read_text():
    hp = pathlib.Path.cwd()
    np = hp / 'test'
    print(np)
    d = {}
    with np.open(mode='r', encoding="utf-8") as f:
        lines = f.readlines()
        for line in lines:
            s = re.split("\s+", line)
            bankId = s[0]
            bankName = s[1]
            bankNo = s[2]

            tmp = {}
            tmp["bankId"] = bankId
            tmp["bankNo"] = bankNo
            tmp["bankName"] = bankName
            d[bankNo] = tmp
    return d


def write_text(d):
    hp = pathlib.Path.cwd()
    np = hp / 'test3'
    print(np)
    with np.open(mode='w', encoding="utf-8") as f:
        for item in d.values():
            f.write(f"{item}")
            f.write("\n")


if __name__ == '__main__':
    read_file2()
